package com.zx.yixun.pop;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.zx.yixun.R;
import com.zx.yixun.data.ChooseOneBean;
import com.zx.yixun.ui.adapter.ChooseOneAdapter;

import java.util.List;

import razerdp.basepopup.BasePopupWindow;
import razerdp.util.animation.AnimationHelper;
import razerdp.util.animation.ScaleConfig;

public class ChooseOnePop extends BasePopupWindow {
    public ChooseOnePop(Context context, String name, List<ChooseOneBean> list,OnChooseOneLinstener linstener) {
        super(context);
        TextView tv_name = findViewById(R.id.tv_name);
        RecyclerView recycleview = findViewById(R.id.recycleview);
        tv_name.setText(name);
        recycleview.setLayoutManager(new LinearLayoutManager(context));
        ChooseOneAdapter adapter = new ChooseOneAdapter();
        recycleview.setAdapter(adapter);
        adapter.setNewData(list);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ChooseOneBean bean = (ChooseOneBean) adapter.getData().get(position);
                linstener.choose(bean);
                dismiss();
            }
        });
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.pop_chooseone);
    }

    public interface OnChooseOneLinstener{
        void choose(ChooseOneBean bean);
    }

    @Override
    protected Animation onCreateShowAnimation() {
        return AnimationHelper.asAnimation().withScale(ScaleConfig.CENTER)
                .toShow();
    }

    @Override
    protected Animation onCreateDismissAnimation() {
        return AnimationHelper.asAnimation().withScale(ScaleConfig.CENTER)
                .toDismiss();
    }

}
